<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="org.tobuy.vo.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'showItemInfo.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="styles_rate.css">
	
	<%
		User seller = (User)request.getAttribute("seller");
		List<Score> scores = (ArrayList<Score>)request.getAttribute("scores");
		Item item = (Item)request.getAttribute("item");
		String score_info = new String();
		int sum_score = 0;
		int avg_score = 0;
		Iterator<Score> iter = scores.iterator();
		while(iter.hasNext()){
			Score score = iter.next();
			sum_score = score.getScore_value()+sum_score;
		}
		if(scores.size()!=0){avg_score = sum_score/scores.size();}
		
		score_info = avg_score + "/" + scores.size();
	 %>


  <br>
  <h3>Item Information</h3>
    
    <%
    	if(request.getAttribute("item") instanceof Book){
			Book book = new Book();
			book = (Book)request.getAttribute("item");
			%>
				<table>
					<tr>
						<td>Type:</td>
						<td><%=book.getType() %></td>
					</tr>
					<tr>
						<td>Name:</td>
						<td><%=book.getItem_name() %></td>
					</tr>
					<tr>
						<td>ID:</td>
						<td><%=book.getItem_id() %></td>
					</tr>
					<tr>
						<td>Price:</td>
						<td><%=book.getPrice() %></td>
					</tr>
					<tr>
						<td>Seller:</td>
						<td><%=book.getSeller_id() %></td>
					</tr>
					<tr>
						<td>ISBN:</td>
						<td><%=book.getIsbn() %></td>
					</tr>
					<tr>
						<td>Author</td>
						<td><%=book.getAutor() %></td>
					</tr>
					<tr>
						<td>Verlag:</td>
						<td><%=book.getVerlag() %></td>
					</tr>
					<tr>
						<td>Gebund:</td>
						<td><%=book.getGebunden() %></td>
					</tr>
					<tr>
						<td>Description:</td>
						<td><%=book.getBeschreibung() %></td>
					</tr>
				
			<%
		}
		if(request.getAttribute("item") instanceof Game){
			Game game = new Game();
			game = (Game)request.getAttribute("item");
			%>
				<table>
					<tr>
						<td>Type:</td>
						<td><%=game.getType() %></td>
					</tr>
					<tr>
						<td>Name:</td>
						<td><%=game.getItem_name() %></td>
					</tr>
					<tr>
						<td>ID:</td>
						<td><%=game.getItem_id() %></td>
					</tr>
					<tr>
						<td>Price:</td>
						<td><%=game.getPrice() %></td>
					</tr>
					<tr>
						<td>Seller:</td>
						<td><%=game.getSeller_id() %></td>
					</tr>
					<tr>
						<td>Age Restriction:</td>
						<td><%=game.getAge_restriction() %></td>
					</tr>
					<tr>
						<td>Platteform</td>
						<td><%=game.getPlatteform() %></td>
					</tr>
					<tr>
						<td>Catigory:</td>
						<td><%=game.getCatigory() %></td>
					</tr>
					<tr>
						<td>Producer:</td>
						<td><%=game.getProducer() %></td>
					</tr>
					<tr>
						<td>Description:</td>
						<td><%=game.getBeschreibung() %></td>
					</tr>
			<%
		}
		if(request.getAttribute("item") instanceof Dvd){
			Dvd dvd = new Dvd();
			dvd= (Dvd)request.getAttribute("item");
			%>
				<table>
					<tr>
						<td>Type:</td>
						<td><%=dvd.getType() %></td>
					</tr>
					<tr>
						<td>Name:</td>
						<td><%=dvd.getItem_name() %></td>
					</tr>
					<tr>
						<td>ID:</td>
						<td><%=dvd.getItem_id() %></td>
					</tr>
					<tr>
						<td>Price:</td>
						<td><%=dvd.getPrice() %></td>
					</tr>
					<tr>
						<td>Seller:</td>
						<td><%=dvd.getSeller_id() %></td>
					</tr>
					<tr>
						<td>Age Restriction:</td>
						<td><%=dvd.getAge_restriction() %></td>
					</tr>
					<tr>
						<td>PlayTime:</td>
						<td><%=dvd.getPlay_time() %></td>
					</tr>
					<tr>
						<td>Region:</td>
						<td><%=dvd.getRegion() %></td>
					</tr>
					<tr>
						<td>Producer:</td>
						<td><%=dvd.getProducer() %></td>
					</tr>
					<tr>
						<td>Description:</td>
						<td><%=dvd.getBeschreibung() %></td>
					</tr>
			<%
		}
     %>
		<tr>
			<td>Rate:</td>
			<td>    
			<% 
			for(int i = 0; i<avg_score;i++){
			%>
				<a class="yellow" href="AddScore?score_value=<%=i+1 %>&score_type=item&target_id=<%=item.getItem_id() %>"></a>
			<%
			}
			for(int i =avg_score+1; i<6;i++){
			%>
				<a class="gray" href="AddScore?score_value=<%=i %>&score_type=item&target_id=<%=item.getItem_id() %>"></a>
			<%
			}
			%>
    		<%=score_info %>
    		</td>
		</tr>
    	 </table>

    	<h4><a href="DirectBuy?item_id=<%=item.getItem_id() %>">direct buy</a></h4>
   
  </body>
</html>
